<?php
	class idea extends spController
	{
		function __construct()
		{
				// 必须加入启动父类构造函数的操作
				parent::__construct();
				 
				// 开始全局操作
				$this->arr_cat = Product_Cat();
				$this->a = $_GET['a'];
				$this->c = $_GET['c'];
				
		}

		function index()
		{
			$m_idea = spClass("m_idea");
			$this->results = $m_idea->spPager($this->spArgs('page', 1), 50)->findAll();
			$this->pager = $m_idea->spPager()->getPager();
			$this->display("idea_list.html");
		}

		function post()
		{
			$m_idea = spClass("m_idea");
			if(!empty($_POST)) {
				if(empty($_POST['content'])) $this->error('提交数据不正确', spUrl('idea', 'post'));
				$_POST['addtime'] = date('Y-m-d H:i:s', time());
				$m_idea->create($_POST);
				$this->success('提交成功', spUrl('idea'));
			} else {
				$this->display("idea_post.html");
			}
		}

		function weibolist()
		{
			$m_weibo = spClass("m_weibo");
			$this->results = $m_weibo->spPager($this->spArgs('page', 1), 50)->findAll();
			$this->pager = $m_weibo->spPager()->getPager();
			$this->display("w_list.html");
		}

		function weibo_post()
		{
			$m_weibo = spClass("m_weibo");
			if(!empty($_POST)) {
				if(empty($_POST['url'])) $this->error('URL必须填写', spUrl('idea', 'weibo_post'));
				$_POST['addtime'] = date('Y-m-d H:i:s', time());
				$m_attachment = spClass('attachment');
				$_POST['thumb'] = $m_attachment->upload('thumb');
				$m_weibo->create($_POST);
				$this->success('提交成功', spUrl('idea'));
			} else {
				$this->display("admin/weibo_post.html");
			}
		}

		function weibo_edit()
		{
			$m_weibo = spClass("m_weibo");
			if(!empty($_POST)) {
				if(empty($_POST['url'])) $this->error('URL必须填写', spUrl('idea', 'weibo_post'));
				$_POST['addtime'] = date('Y-m-d H:i:s', time());
				$m_attachment = spClass('attachment');
				$_POST['thumb'] = $m_attachment->upload('thumb');
				$m_weibo->create($_POST);
				$this->success('提交成功', spUrl('idea'));
			} else {
				$w_id = intval($_GET['w_id']);
				$this->result = $m_weibo->find(array('w_id'));
				$this->display("admin/weibo_edit.html");
			}
		}
	}
?>